package com.ypf.rpc;

import com.ypf.rpc.manager.client.ClientProxy;
import com.ypf.rpc.manager.client.RpcClientManager;
import com.ypf.rpc.message.RpcRequestMessage;
import com.ypf.rpc.service.HelloService;
import com.ypf.rpc.service.HelloServiceImpl;

public class RpcClient {
    public static void main(String[] args) {
        RpcClientManager clientManager = new RpcClientManager();

//        RpcRequestMessage msg = new RpcRequestMessage(
//                1,
//                "com.ypf.rpc.service.HelloServiceImpl",
//                "sayHello",
//                String.class,
//                new Class[]{String.class},
//                new Object[]{"zhangsan"}
//        );
//
//        try {
//            clientManager.sendRpcRequest(msg);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }


        // 创建代理对象
        HelloService service = new ClientProxy(clientManager).getProxyService(HelloServiceImpl.class);
        System.out.println(service.sayHello("ypf"));
        System.out.println(service.sayHello("zhangsan"));   // 发两条数据测试负载均衡

//        try {
//            Thread.sleep(10000);
//            RpcClientManager.channels.forEach((key,channel)->{
//                System.out.println("Active:"+channel.isActive());
//            });
//            System.out.println(service.sayHello("ypf"));
//            System.out.println(service.sayHello("zhangsan"));
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }

    }
}
